The SB-Prolog library contains various other utilities,
some of which are listed below.
- $append(X, Y, Z)
- $append/3 (L)
Succeeds if list Z is the concatenation of lists X and Y.
- $member(X, L)
- $member/2 (L)
Checks whether X unifies with any element of list L,
succeeding more than once if there are multiple such elements.
- $memberchk(X, L)
- $memberchk/2 (L)
Similar to $member/2, except that $memberchk/2 is
deterministic, i.e. does not succeed more than once for any call.
- $reverse(L, R)
- $reverse/2 (L)
Succeeds if R is the reverse of list L.
If L is not a fully determined list,
i.e. if the tail of L is a variable,
this predicate can succeed arbitrarily many times.
- $merge(X, Y, Z)
- $merge/3 (L)
Succeeds if Z is the list resulting from ``merging'' lists X and Y,
i.e. the elements of X together with any element of Y
not occurring in X.
If X or Y contain duplicates, Z may also contain duplicates.
- $absmember(X, L)
- $absmember/2 (L)
Similar to $member/2, except that it checks for identity
(through ==/2)
rather than unifiability (through =/2) of X with elements of L.
- $nthmember(X, L, N)
- $nthmember/3 (L)
Succeeds if the Nth element of the list L unifies with X.
Fails if N is greater than the length of L.
Either X and L, or L and N, should be instantiated at the
time of the call.
- $member2(X, L)
- $member2/2 (L)
Checks whether X unifies with any of the actual elements of L.
The only difference between this and $member/2 is on lists with
a variable tail, e.g.
[a, b, c | _ ]
:
while $member/2 would insert X at the end of such a list
if it did not find it, $member2/2 only checks for membership
but does not insert it into the list if it is not there.
- length(L, N)
- length/2 (L)
Succeeds if the length of the list L is N.
This predicate is deterministic if L is instantiated to a list
of definite length,
but is nondeterministic if L is a variable or has a variable tail.
- subsumes(X, Y)
- subsumes/2 (L)
Succeeds if the term X subsumes the term Y
(i.e. if Y is an instance of X).